#include <iostream>
#include <map>
#include <cstdio>
using namespace std;

long long n;
map<string, long long> num;

bool j( string s )
{
	long long a = 0, b = 0;
	for( long long i = 0; i < s.length(); i++ )
	{
		if( s[i] == '.' )
		{
			a++;
		}
		else if( s[i] == ':' )
		{
			b++;
			if( a != 3 )
			{
				return 0;
			}
		}
		else if( !( s[i] >= '0' && s[i] <= '9' ) )
		{
			return 0;
		}
	}
	if( a != 3 )
	{
		return 0;
	}
	if( b != 1 )
	{
		return 0;
	}
	long long tmp = 0, num = 0, cnt = 0;
	if( s[tmp] == '.' || s[tmp] == ':' )
	{
		return 0;
	}
	while( s[tmp] != '.' && s[tmp] != ':' )
	{
		num *= 10;
		num += s[tmp] - '0';
		tmp++;
		cnt++;
	}
	if( !( num >= 0 && num <= 255 ) )
	{
		return 0;
	}
	if( num == 0 && cnt >= 2 )
	{
		return 0;
	}
	else if( num != 0 && s[tmp - cnt] == '0' )
	{
		return 0;
	}
	tmp++, cnt = 0;
	if( s[tmp] == '.' || s[tmp] == ':' )
	{
		return 0;
	}
	num = 0;
	while( s[tmp] != '.' && s[tmp] != ':' )
	{
		num *= 10;
		num += s[tmp] - '0';
		tmp++;
		cnt++;
	}
	if( !( num >= 0 && num <= 255 ) )
	{
		return 0;
	}
	if( num == 0 && cnt >= 2 )
	{
		return 0;
	}
	else if( num != 0 && s[tmp - cnt] == '0' )
	{
		return 0;
	}
	tmp++, cnt = 0;
	if( s[tmp] == '.' || s[tmp] == ':' )
	{
		return 0;
	}
	num = 0;
	while( s[tmp] != '.' && s[tmp] != ':' )
	{
		num *= 10;
		num += s[tmp] - '0';
		tmp++;
		cnt++;
	}
	if( !( num >= 0 && num <= 255 ) )
	{
		return 0;
	}
	if( num == 0 && cnt >= 2 )
	{
		return 0;
	}
	else if( num != 0 && s[tmp - cnt] == '0' )
	{
		return 0;
	}
	tmp++, cnt = 0;
	if( s[tmp] == '.' || s[tmp] == ':' )
	{
		return 0;
	}
	num = 0;
	while( s[tmp] != '.' && s[tmp] != ':' )
	{
		num *= 10;
		num += s[tmp] - '0';
		tmp++;
		cnt++;
	}
	if( !( num >= 0 && num <= 255 ) )
	{
		return 0;
	}
	if( num == 0 && cnt >= 2 )
	{
		return 0;
	}
	else if( num != 0 && s[tmp - cnt] == '0' )
	{
		return 0;
	}
	tmp++, cnt = 0;
	if( tmp >= s.length() )
	{
		return 0;
	}
	num = 0;
	while( tmp < s.length() )
	{
		num *= 10;
		num += s[tmp] - '0';
		tmp++;
		cnt++;
	}
	if( !( num >= 0 && num <= 65535 ) )
	{
		return 0;
	}
	if( num == 0 && cnt >= 2 )
	{
		return 0;
	}
	else if( num != 0 && s[tmp - cnt] == '0' )
	{
		return 0;
	}
	return 1;
}

int main()
{
	freopen( "network.in", "r", stdin );
	freopen( "network.out", "w", stdout );
	cin >> n;
	for( long long i = 1; i <= n; i++ )
	{
		string op, ipadr;
		cin >> op >> ipadr;
		if( !j( ipadr ) )
		{
			cout << "ERR" << endl;
			continue;
		}
		if( op == "Client" )
		{
			if( num[ipadr] )
			{
				cout << num[ipadr] << endl;
			}
			else
			{
				cout << "FAIL" << endl;
			}
		}
		else
		{
			if( num[ipadr] )
			{
				cout << "FAIL" << endl;
			}
			else
			{
				num[ipadr] = i;
				cout << "OK" << endl;
			}
		}
	}
	return 0;
}

// I LOVE "NETWORK" BECAUSE I SPENT 114514 HOURS SOLVING IT!!!
